Laboratory 5
Last updated February 17, 2023
Name: Aidan Leib
Email: pleib@purdue.edu
import numpy as np
Amplitude modulation is the process of multiplying a CT signal by a another signal $c(t)$ called a "carrier."
If the signal is denoted by $x(t)$, then the modulated signal $y(t)$ is given by
For example, we can modulate a signal $x(t)$ using a cosine carrier $c(t)=\cos (2 \pi f_0 t) $ with frequency $f_0$. Then the modulated signal $y(t)$ is given by
$$ y(t)=x(t) \cos (2 \pi f_0 t) .$$As you may have learned in your companion course (e.g. ECE301), periodic carriers play a special role in signal processing as they can be used to shift the frequencies of a signal. This is because of the multiplication property of the Fourier transform/series. We will come back to the idea of shifting frequencies at the end of this lab. But first, let us explore a fun and intuitive effect that can be created with amplitude modulation: the tremolo effect (also called "beat effect").
When the frequency of the carrier $c(t)$ is low, more specifically when it is below the audible range (the audible range is about 20Hz to 20KHz), then modulation creates a "tremolo" effect" on the original signal. This is something you can hear if $x(t)$ is an audio signal. It sounds like one is turning the volume up and down, periodically. Let's try it out!
Let $x(t)= \sin 2 \pi 440 t$ (this is a middle A). Play it. Now consider the carrier $c(t)=\cos (2 \pi f_0 t )$ with $f_0=2 Hz$. Play the modulated sound $y(t)= x(t) c(t).$
from IPython.display import Audio
t = np.linspace(0, 5, 5 * 44100)
x = np.sin(2 * np.pi * 440 * t)
y = x * np.cos(2 * np.pi * 2 * t)
Audio(y, rate=44100)
Change the frequency $f_0$. Compare what happens when the frequency is very low (<20Hz) and when it is very high (20-20kHZ).
f_0 = 1
y = x * np.cos(2 * np.pi * f_0 * t)
Audio(y, rate=44100)
f_0 = 4000
y = x * np.cos(2 * np.pi * f_0 * t)
Audio(y, rate=44100)
When the frequency is low, we get a very nice "beat" effect, but when it is high we get a sine wave at the modulation frequency.
Create a sine wave of frequency 220Hz, and modulate it with $c(t)=\cos (2 \pi f_0 t )$
f_0 = 2
x = np.sin(2 * np.pi * 220 * t)
y = x * np.cos(2 * np.pi * f_0 * t)
Audio(y, rate=44100)
Create a periodic triangular wave with frequency of 3 Hz. The area of each triangle should be equal to one. Play the triangular wave. Change the triagular wave frequency and play the resulting modulated sound.
import matplotlib.pyplot as plt
def triangle(freq, t):
T = 1 / freq
amplitude = 8 / T
return amplitude * (2 * np.abs(t / T - np.floor(t / T + 1 / 2)) - 0.5)
f_0 = 3
x = triangle(f_0, t)
plt.plot(t, x)
Audio(x, rate=44100)
f_0 = 40
x = triangle(f_0, t)
plt.plot(t, x)
Audio(x, rate=44100)
Modulate a middle A with the triangular wave you created in the previous exercise. Play the modulated sound. Change the triagular wave frequency and play the resulting modulated sound. Compare what happens when the frequency is very low (<20Hz) and when it is very high (20-20kHZ).
a = np.cos(2 * np.pi * 440 * t)
y = a * triangle(3, t)
Audio(y, rate=44100)
y = a * triangle(10000, t)
Audio(y, rate=44100)
When the frequency of the modulation is very low, we get a very pronounced "beat" effect. When the mod frequency is high, it overshadows the original fruency so we just get a triangle wave at the modulation frequency for an output.
Create a periodic square wave with frequency of 3 Hz. The square should occupy half of the period. Play the square wave.
freq = 3
amplitude = 2 * freq
x = np.sin(2 * np.pi * freq * t)
x = np.sign(x) * amplitude
plt.plot(t, x)
[<matplotlib.lines.Line2D at 0x7f88cba58c10>]
Modulate a middle A with the square wave you created in the previous exercise. Play the modulated sound.
y = a * x
Audio(y, rate=44100)
Because of the properties of complex exponentials, multiplying a signal by a periodic carrier signal results in changing the frequencies of the components of the signal.
For example, multiplying two sine wave together is the same as adding a wave at their average frequency and a wave at their frequency difference.
Indeed, we have
$$ \sin\left( 2 \pi f_1 t \right) \sin \left( 2 \pi f_2 t \right) = \frac{1}{2}\cos \left( 2 \pi (f_1-f_2) t \right) - \frac{1}{2}\cos \ \left( 2 \pi (f_1+f_2) t \right).$$In other words, the frequency $f_1$ in the signal $\sin \left( 2\pi f_1 t\right)$ is divided into two components which are "shifted" to new frequencies on either sides of $f_1$; the extent of the shift is given by the carrier frequency $f_2$.
Prove the above formula. Hint: Transform the sines into complex exponentials.
Given that $$\sin(x) = \frac{e^{ix} - e^{-ix}}{2i}$$
Define $x_1 = 2\pi f_1t$, $x_2 = 2\pi f_2t$ $$\sin(x_1)\sin(x_2) = \left( \frac{e^{ix_1} - e^{-ix_1}}{2i} * \frac{e^{ix_2} - e^{-ix_2}}{2i} \right)$$
We know cosine can be written as, $$\cos(x) = \frac{e^{ix} + e^{-ix}}{2}$$
Therefore, $$ = - \frac{1}{2} \cos(x_1 + x_2) + \frac{1}{2} \cos(x_1 - x_2)$$
Plugging in for $x_1$ and $x_2$,
$$\sin\left( 2 \pi f_1 t \right) \sin \left( 2 \pi f_2 t \right) = - \frac{1}{2} \cos(2 \pi f_1 t + 2 \pi f_2 t) + \frac{1}{2} \cos(2 \pi f_1 t - 2 \pi f_2 t)$$Do not skip this section! Lab will be graded only on completion of this section.
__1. What parts of the lab, if any, do you feel you did well?